﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;

namespace IReklamo
{
    public class IReklamoDbContext : DbContext
    {
        public IReklamoDbContext() : base("IReklamoConnectionString") { }

        public DbSet<Complaint> Complaints {get;set;}
        public DbSet<Visual> Visuals {get;set;}
        public DbSet<Support> Supports { get; set; }
        public DbSet<Comment> Comments { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

            modelBuilder.Entity<Complaint>().ToTable("Complaints");
            modelBuilder.Entity<Complaint>()
                .HasKey(x => x.Id)
                .Property(e => e.Id).HasColumnName("ComplaintId");
            modelBuilder.Entity<Complaint>().Ignore(c => c.TotalSupports);
            modelBuilder.Entity<Complaint>().Ignore(c => c.TotalDislikes);
            modelBuilder.Entity<Complaint>().Ignore(c => c.TotalComments);

            modelBuilder.Entity<SponsoredComplaint>().ToTable("SponsoredComplaints");
            modelBuilder.Entity<SponsoredComplaint>().HasKey(r => r.Id);

            modelBuilder.Entity<Visual>().ToTable("Visuals");
            modelBuilder.Entity<Visual>().HasKey(x => x.Id)
                .Property(e => e.Id).HasColumnName("VisualId");

            modelBuilder.Entity<Support>().ToTable("Supports");
            modelBuilder.Entity <Support>().HasKey(x => x.Id);

            modelBuilder.Entity<Dislike>().ToTable("Dislikes");
            modelBuilder.Entity<Dislike>().HasKey(x => x.Id);

            modelBuilder.Entity<Comment>().ToTable("Comments");
            modelBuilder.Entity<Comment>().HasKey(x => x.Id);
        }
    }
}
